package com.easylinkin.linkappapi.grid.controller;

import com.easylinkin.linkappapi.grid.entity.GridReportDayUser;
import com.easylinkin.linkappapi.grid.service.IGridReportDayUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Setter;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.Arrays;


/**
 * 网格日报人员指定表 前端控制器
 *
 * @author kuyujie
 * @since 2024-05-16
 */
@Api(tags = "网格日报人员指定表")
@Setter(onMethod_ = @Resource)
@RestController
@RequestMapping("/grid/gridReportDayUser")
public class GridReportDayUserController {
    private IGridReportDayUserService gridReportDayUserService;

    /**
     *   通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value="通过id删除", notes="通过id删除")
    @DeleteMapping(value = "/delete")
    public RestMessage delete(@RequestParam("id") Integer id) {
        gridReportDayUserService.removeById(id);
        return RestBuilders.successBuilder().message("删除成功").build();
    }

    /**
     *  批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value="批量删除", notes="批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public RestMessage deleteBatch(@RequestParam("ids") String ids) {
        this.gridReportDayUserService.removeByIds(Arrays.asList(ids.split(",")));
        return RestBuilders.successBuilder().message("批量删除成功").build();
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value="通过id查询", notes="通过id查询")
    @GetMapping(value = "/queryById")
    public RestMessage queryById(@RequestParam("id") Integer id) {
        GridReportDayUser gridReportDayUser = gridReportDayUserService.getById(id);
        if(gridReportDayUser == null) {
            return RestBuilders.errorBuilder().message("未找到对应数据").build();
        }
        return RestBuilders.successBuilder().data(gridReportDayUser).build();
    }
}
